# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   selenium_self
# FileName:      read_excel.py
# Author:       test_liu
# Datetime:     2024/8/15 下午6:44
# Description: 读取excel文件
# ---------------------------------------------------------------------------
import json

import openpyxl

from WebTest1.common.read_ini import ReadIni


class ReadExcel:
    def __init__(self, table_name, excel='excel'):
        ini = ReadIni()
        self.excel_path = ini.get_excel(excel)
        table = ini.get_table(table_name)
        self.wb = openpyxl.load_workbook(self.excel_path)
        self.ws = self.wb[table]

    def get_data(self):
        data = []
        min_row = 2
        max_row = self.ws.max_row
        for row in range(min_row, max_row+1):
            row_data = json.loads(self.ws['h'+str(row)].value)
            row_data.append(self.ws['i'+str(row)].value)
            row_data.append(self.ws['a'+str(row)].value)
            row_data.append(row)
            data.append(row_data)
        print(data)
        return data

    def write_date(self, row, res, column="j"):
        self.ws[column+str(row)].value = res
        self.wb.save(self.excel_path)



if __name__ == '__main__':
    # 登录用例表测试
    excel = ReadExcel('login')
    excel.get_data()
    # 竞赛标签用例表测试
    excel = ReadExcel('sign_type')
    excel.get_data()

